package com.gym.myshop.web.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gym.myshop.entity.Type;
import com.gym.myshop.services.TypeServices;
import com.gym.myshop.services.impl.TypeServicesImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author ming
 * 2021/11/6
 * description:商品类别控制
 */
@WebServlet("/type")
public class TypeController extends BaseServlet {
    private TypeServices ts = new TypeServicesImpl();


    /**
     *@author:ming
     *@Date: 2021/11/7
     *@description:品类
     */
    public String getAll(HttpServletRequest request, HttpServletResponse response) {
        try {
            //访问业务处
            List<Type> all = ts.getAll();
            //转换为json字符串
            //1 创建 objectmapper
            ObjectMapper om = new ObjectMapper();
            //2 转换字符串
            String string = om.writeValueAsString(all);
            return string;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

}
